<template>
  <view>
    <BackgroundBar title="收藏" :back="true"></BackgroundBar>

    <ListItem
      v-for="(item, index) of list"
      :key="index"
      :item="item"
      :has-collect="true"
    ></ListItem>
  </view>
</template>

<script setup>
import {ref} from 'vue';
import BackgroundBar from '@/components/NavigationBar/background.vue';
import ListItem from '@/components/PostList/item.vue';
import collectionManagement from '@/api/collectionManagement'
import articleManagement from '@/api/articleManagement'

const list = ref([]);
// 我的收藏
collectionManagement.getAllCollectionsForUser()
  .then(res => {
    console.log("我的收藏", res)
    for (const item of res.data) {
      try {
        const articleId = item.articleId
        articleId && articleManagement.getArticleDetail(articleId)
          .then(res => {
            console.log("收藏详情", res)
            list.value.push(res.data)
          })
          .catch(err => {
            console.log(err)
          })
      } catch (err){
        console.log(err)
      }
    }
  })
  .catch(err => {
    console.log(err)
  })

</script>

<style lang="scss"></style>
